-
Notifications
You must be signed in to change notification settings - Fork 2.3k
feat: add Opaque API and Protobuf Editions support #5723
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is really cool! Please add some test files that set this new option so I can see what the code looks like when it's generated. You'll need to add a new opaque.buf.gen.yaml
or so, see the other generation scripts in examples/internal/proto/examplepb
. Thanks!
@johanbrandhorst, thank you for review! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lets rename the option to align with the Go protobuf plugin
Protolint is failing because the new file isn't formatted, run |
@johanbrandhorst, I’ve fixed the formatting and resolved most of the Bazel build errors. However, one issue remains — it’s caused by the |
Oh boy, Bazel isn't my strong suite either unfortunately. It seems like the error we're seeing is
So the problem is probably setting the right generator options for protoc-gen-go. I don't really know what we need to do here, but I'll CC @AlejoAsd who I know has some Bazel skills :) |
@johanbrandhorst @kop seems like you need to pass I'd assume you don't want to use the Opaque API for all protos in the repository, but scoped to the example folder you touched right? If so, maybe it'd be a good idea to create a new go_proto_compiler(
name = "go_grpc_use_opaque_api",
options = [
"paths=source_relative",
"require_unimplemented_servers=false",
"use_opaque_api=true", # The relevant change
],
plugin = "@org_golang_google_grpc_cmd_protoc_gen_go_grpc//:protoc-gen-go-grpc",
suffix = "_grpc.pb.go",
visibility = ["//visibility:public"],
deps = PROTO_RUNTIME_DEPS + [
"@org_golang_google_grpc//:go_default_library",
"@org_golang_google_grpc//codes:go_default_library",
"@org_golang_google_grpc//status:go_default_library",
],
) And then update the < "//:go_grpc",
---
> "//:go_grpc_use_opaque_api",
168c168 |
Thanks a lot for your input!
Yes, ideally. We might even want to scope it less than that tbh, maybe only the file we're using here. I'd have to dig in a bit more and unfortunately I don't have time right now, but this might be good enough for someone to start on this! |
This pull request introduces significant updates to the code generation logic, with a focus on supporting Protobuf Editions and adding a new "Opaque API" mode for improved flexibility in request handling. Key changes include updating supported features for Protobuf Editions, integrating the
useOpaqueAPI
flag across the generator, and modifying templates to conditionally handle the Opaque API logic.These changes enhance the flexibility and capability of the code generator, ensuring compatibility with the latest Protobuf standards while providing developers with options to tailor the generated code to their specific needs.
References to other Issues or PRs
Fixes #4555
Have you read the Contributing Guidelines?
Yes
Brief description of what is fixed or changed
Protobuf Editions Support:
internal/codegenerator/supported_features.go
: Added support for Protobuf Editions by updatingsupportedCodeGeneratorFeatures
to includeFEATURE_SUPPORTS_EDITIONS
and declaring edition 2023 in the newsupportedEditions
function. Updated methods to include minimum and maximum supported editions in plugin responses.Opaque API Feature:
Generator updates:
protoc-gen-grpc-gateway/internal/gengateway/generator.go
: Introduced theuseOpaqueAPI
field in thegenerator
struct and updated theNew
constructor to accept this parameter. Thegenerate
method now passes theuseOpaqueAPI
option to templates. [1] [2] [3]Template logic:
protoc-gen-grpc-gateway/internal/gengateway/template.go
: Updated various template sections to conditionally handle request and response data based on theUseOpaqueAPI
flag. This includes changes to body decoding, field mask handling, and path/query parameter assignments. [1] [2] [3] [4]Testing:
protoc-gen-grpc-gateway/internal/gengateway/generator_test.go
: Added test cases to validate the behavior of the generator with and without the Opaque API enabled.